package com.asiainfo.dacp.datastash.worker.executor.adapter.datax.model.domain;

import java.util.Map;

import com.asiainfo.dacp.datastash.worker.executor.adapter.datax.model.PluginCatalogType;
import com.asiainfo.dacp.datastash.worker.executor.adapter.datax.utils.CommonErrorCode;
import com.asiainfo.dacp.datastash.worker.executor.adapter.datax.utils.WorkerException;
import com.google.common.collect.Maps;

import lombok.Data;

@Data
public class StepPair { 

	private Map<PluginCatalogType, Step> repo = Maps.newConcurrentMap();
	
	private StepPair next;

	public StepPair(Step reader, Step writer) {
		if (reader.getType() != PluginCatalogType.READER || writer.getType() != PluginCatalogType.WRITER) {
			throw WorkerException.asDataXException(CommonErrorCode.RUNTIME_ERROR,
					String.format("构造错误. reaer名称: %s, 类型: %s; reaer名称: %s, 类型: %s .", 
							reader.getName(), reader.getType(), writer.getName(), writer.getType()));
		}
		repo.put(PluginCatalogType.READER, reader);
		repo.put(PluginCatalogType.WRITER, writer);
	}
	public StepPair(Step dp) {
		if (dp.getType() != PluginCatalogType.DPEXECUTOR ) {
			throw WorkerException.asDataXException(CommonErrorCode.RUNTIME_ERROR,
					String.format("构造错误. reaer名称: %s, 类型: %s; reaer名称: %s, 类型: %s .", 
							dp.getName(), dp.getType(), dp.getName(), dp.getType()));
		}
		repo.put(PluginCatalogType.DPEXECUTOR, dp);
	}
	public Step reader(){
		return repo.get(PluginCatalogType.READER);
	}
	public Step writer(){
		return repo.get(PluginCatalogType.WRITER);
	}
	public Step dp(){
		return repo.get(PluginCatalogType.DPEXECUTOR);

	}
	
}
